package lab1.io;

import config.Config;
import operations.FileOperations;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileIO2 {

    public static final int TESTS_NUMBER = 1000;
    public static final String RES_FILE = "FileIO2.bin";


    /**
     * Copy file on the local computer.
     * This method is faster than FileIO.
     * Method calculate time of copying using IO.
     *
     * @param args
     */
    public static void main(String[] args) {
        for (int k = 0; k < TESTS_NUMBER; k++) {

            try {
                File f = new File(RES_FILE);
                FileOperations.getEmptyFile(f);

                try (
                    FileOutputStream fout = new FileOutputStream(f);
                    FileInputStream fin = new FileInputStream(Config.INITIAL_FILE);
                ) {
                    long start = System.currentTimeMillis();

                    byte[] contentInBytes = new byte[fin.available()];
                    fin.read(contentInBytes);
                    fout.write(contentInBytes);

                    long end = System.currentTimeMillis();
                    System.out.println(end - start);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
            }
        }
    }
}
